<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>读了么！-确认订单</title>
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <link href="style/order.css" rel="stylesheet" type="text/css">
    <!--<script type="text/javascript" src="js/jquery-1.12.0.min.js"></script>-->
    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.4.1.js"></script>
    <script src="layui/layui.js" charset="utf-8"></script>
</head>
<body>
<div class="order">
    <div class="selectAddress">
        <h2>选择收货地址：</h2>
        <div style="margin-left: 50px">
            <button id="btn1">选择我的收货地址</button>
            <button id="btn2" onclick="naddress()">添加新的收货地址</button>
        </div>
    </div>
    <script>
        $(document).ready(function () {
            var userId = 100020;
            var deliveryId = 0;
            $.ajax({
                url: '/show/address',
                method: 'post',
                dataType: 'json',
                data: {'userId': userId},
                success: function (data) {
                    alert(data[0].country);
                    $.each(data, function (i, item) {
                        var deliveryId = item.deliveryId;
                        var name = item.name;
                        var country = item.country;
                        var county = item.county;
                        var province = item.province;
                        var city = item.city;
                        var street = item.street;
                        var detailedAddress = item.detailedAddress;
                        var phoneNumber = item.phoneNumber;
                    });
                }
            });
        });
    </script>
    <div class="orderOK">
        <h2>确认订单信息：</h2>
        <div class="head">
            <span class="span1">店铺商品</span>
            <span class="span2">单价</span>
            <span class="span3">数量</span>
            <span class="span4">小计</span>
        </div>
        <div class="order-order">
        </div>
        <script>
            $(document).ready(function () {
                var userId = 0;
                $.ajax({
                    url: '/user/order',
                    dataType: 'json',
                    method: 'post',
                    data: {'userId': userId},
                    success: function (data) {
                        $.each(data.books, function (i, item) {
                            var shopName = item.shopName;
                            var bookName = item.bookName;
                            var price = item.price;//单价
                            var totalPrice = data.totalPrice;//小计
                            var count = data.count;//数量
                            console.log(shopName);
                            $(".order-order").append("<div class=''>" + shopName + "</div>" + "<div>" + bookName + price + count + "</div>");
                            $("#total").text(totalPrice)
                        })
                    }
                });
            });
        </script>
        <div class="allInfo">
            <h1>实付款：</h1>
            <a style="color: #4E5465;font-size: 22px;margin-left: 70px">￥</a>
            <a style="color: red;font-size: 30px" id="total"></a>
        </div>
        <div class="btnSubmit">
            <a href="#" style="border: 1px dotted red">返回购物车</a>
            <input type="submit" value="提交订单并去支付" class="btn" onclick="pay()">
        </div>
    </div>
</div>
<script>
   function pay(){
       $.ajax({
           url: '/price/total',
           dataType: 'json',
           method: 'post',
           data: {'userId': 1},
           success: function (data) {
                if (data.result=="1"){
                    window.location.href="pay.jsp";
                }
           }
       });
    }

    function naddress() {
        window.location.href="Add_Address.jsp";
    }
</script>
</body>
</html>
